/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import merlion.crm.slcm.entity.Address;

/**
 *
 * @author Yuwei
 */
@Entity
public class RawMaterialPurchaseOrder implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String poNum;
    private Timestamp poDate;
    private Boolean currency; //TRUE = SGD, FALSE = USD
    private Boolean urgent;
    private String comments;
    private Double subtotalSGD;
    private Double taxSGD;
    private Double totalSGD;
    private Double subtotalUSD;
    private Double taxUSD;
    private Double totalUSD;
    private Timestamp hiddenId;
    @OneToMany(targetEntity = RawMaterialItemLine.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private List<RawMaterialItemLine> itemLines;
    @OneToOne(targetEntity = Address.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Address address;
    @OneToOne(mappedBy = "rmPo")
    private RawMaterialRequestForQuotation rawMaterialRequestForQuotation;
    @ManyToOne(targetEntity = Supplier.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Supplier supplier;
    @OneToOne(targetEntity = RawMaterialSalesOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private RawMaterialSalesOrder rmso;

    public RawMaterialPurchaseOrder() {
        poNum = "";
        poDate = new Timestamp(new Date().getTime());
        address = new Address();
        rawMaterialRequestForQuotation = null;
        supplier = new Supplier();
        itemLines = new ArrayList<RawMaterialItemLine>();
        rmso = null;

        Random rand = new Random();
        long seed = new Date().getTime() + (long) rand.nextInt(10000);
        hiddenId = new Timestamp(seed);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Boolean getUrgent() {
        return urgent;
    }

    public void setUrgent(Boolean urgent) {
        this.urgent = urgent;
    }

    public Timestamp getPoDate() {
        return poDate;
    }

    public Boolean getCurrency() {
        return currency;
    }

    public void setCurrency(Boolean currency) {
        this.currency = currency;
    }

    public void setPoDate(Timestamp poDate) {
        this.poDate = poDate;
    }

    public String getPoNum() {
        return poNum;
    }

    public void setPoNum(String poNum) {
        this.poNum = poNum;
    }

    public RawMaterialRequestForQuotation getRawMaterialRequestForQuotation() {
        return rawMaterialRequestForQuotation;
    }

    public void setRawMaterialRequestForQuotation(RawMaterialRequestForQuotation rawMaterialRequestForQuotation) {
        this.rawMaterialRequestForQuotation = rawMaterialRequestForQuotation;
    }

    public List<RawMaterialItemLine> getItemLines() {
        return itemLines;
    }

    public void setItemLines(List<RawMaterialItemLine> itemLines) {
        this.itemLines = itemLines;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public Double getSubtotalSGD() {
        return subtotalSGD;
    }

    public void setSubtotalSGD(Double subtotalSGD) {
        this.subtotalSGD = subtotalSGD;
    }

    public Double getSubtotalUSD() {
        return subtotalUSD;
    }

    public void setSubtotalUSD(Double subtotalUSD) {
        this.subtotalUSD = subtotalUSD;
    }

    public Double getTaxSGD() {
        return taxSGD;
    }

    public void setTaxSGD(Double taxSGD) {
        this.taxSGD = taxSGD;
    }

    public Double getTaxUSD() {
        return taxUSD;
    }

    public void setTaxUSD(Double taxUSD) {
        this.taxUSD = taxUSD;
    }

    public Double getTotalSGD() {
        return totalSGD;
    }

    public void setTotalSGD(Double totalSGD) {
        this.totalSGD = totalSGD;
    }

    public Double getTotalUSD() {
        return totalUSD;
    }

    public void setTotalUSD(Double totalUSD) {
        this.totalUSD = totalUSD;
    }

    public RawMaterialSalesOrder getRmso() {
        return rmso;
    }

    public void setRmso(RawMaterialSalesOrder rmso) {
        this.rmso = rmso;
    }

    public Timestamp getHiddenId() {
        return hiddenId;
    }

    public void setHiddenId(Timestamp hiddenId) {
        this.hiddenId = hiddenId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof RawMaterialPurchaseOrder)) {
            return false;
        }
        RawMaterialPurchaseOrder other = (RawMaterialPurchaseOrder) object;
        // Compare hiddenId
        if(!this.hiddenId.equals(other.hiddenId))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.RawMaterialPurchaseOrder[ id=" + id + " ]";
    }
}
